package com.xteam.xnetworkdisk.sys.controller;

import com.xteam.xnetworkdisk.sys.service.ShareService;
import com.xteam.xnetworkdisk.utils.R;
import com.xteam.xnetworkdisk.vo.ShareFileVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分享控制器类
 * 处理文件分享相关的请求
 *
 * 作者：xiaozhiyong
 * 邮箱：xiaozhiyong03@gmail.com
 * 日期：2024-08-04 15:56:30
 */
@RestController
@RequestMapping("sys/share")
public class ShareController {

    @Resource
    private ShareService shareService;
    /**
     * 获取用户分享的文件列表
     *
     * @param shareId 用户ID
     * @return 分享文件列表
     */
    @PostMapping("/list")
    public R getShareFileList(@RequestParam String shareId) {
        return shareService.getSharedFiles(shareId);
    }

    /**
     * 分享指定的文件
     *
     * @param shareFileVO 文件ID
     *
     * @return 文件分享结果
     */
    @PostMapping("/shareFile")
    public R shareFile(@RequestBody ShareFileVO shareFileVO) {
        List<Integer> fileIds = shareFileVO.getFileIds();
        String shareName = shareFileVO.getShareName();
        return R.ok("分享成功").put("shareId", shareService.shareFileById(fileIds,shareName));
    }

    /**
     * 取消对指定文件的分享
     * @return 文件分享取消结果
     */
    @PostMapping("/cancelShare")
    public R cancelShare(@RequestParam List<Integer> shareIds) {
        // 这里实现取消分享的逻辑
        shareService.cancelShared(shareIds);
        return R.ok("取消分享成功");
    }


    @PostMapping("/deleteShare")
    public R deleteShare(@RequestParam List<Integer> shareIds) {
        shareService.deleteShare(shareIds);
        return R.ok("删除成功");
    }
    /**
     * 获取分享目录
     * @return
     */
    @GetMapping("/myShare")
    public R myShare() {
        return shareService.getMyShared();
    }

    /**
     * 保存到我的网盘
     * @param fileIds
     * @param folderId
     * @return
     */
    @PostMapping("/saveToMySpace")
    public R saveToMySpace(@RequestParam List<Integer> fileIds,@RequestParam Integer folderId) {
        return  shareService.saveTo(fileIds,folderId);
    }
}
